/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */


package org.amarena2d.examples.scenes;

import com.android1.amarena2d.commons.Tools;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.android1.amarena2d.nodes.sprites.Sprite;
import com.android1.amarena2d.nodes.ui.VirtualDigitalPad;
import com.android1.amarena2d.texture.Textures;
import com.badlogic.gdx.graphics.Color;
import org.amarena2d.examples.Example;

@Example(name = "Virtual Digital Pad", category = "Input")
public class VirtualDPadExampleScene extends Scene {

    final Sprite sprite;
    final VirtualDigitalPad pad;
    final VirtualDigitalPad pad2;

    public VirtualDPadExampleScene() {

        //will make a white backgroundcolor
        engine.getRenderer().setClearColor(Color.WHITE);

        add(new SimpleLabel("(Use the dpads to move and rotate the sprite)", 120, 20, Color.BLACK));

        sprite = new Sprite(Textures.$("andou_die02.png").get(), 200, 150);
        sprite.transform().setTransformAnchor(32, 22);
        add(sprite);

        Sprite vdpadBase = new Sprite(Textures.$("dpad_base.png").get(), 10, 10);
        Sprite vdpadKnob = new Sprite(Textures.$("dpad_knob.png").get(), 50, 50);
        pad = new VirtualDigitalPad(vdpadBase, vdpadKnob);
        add(vdpadBase, vdpadKnob);

        pad.setListener(new VirtualDigitalPad.Listener() {
            @Override
            public void onChange(VirtualDigitalPad pad, float radius, float directionX, float directionY) {
//                sprite.setRotation(Tools.radiansToDegrees((float) Math.atan2(directionX, directionY)));
                sprite.move().with(directionX * radius * 2, directionY * radius * 2);

            }
        });


        Sprite vdpadBase2 = new Sprite(Textures.$("dpad_base.png").get(), 320, 180);
        Sprite vdpadKnob2 = new Sprite(Textures.$("dpad_knob.png").get(), 50, 50);
        pad2 = new VirtualDigitalPad(vdpadBase2, vdpadKnob2);
        add(vdpadBase2, vdpadKnob2);

        pad2.setListener(new VirtualDigitalPad.Listener() {
            @Override
            public void onChange(VirtualDigitalPad pad, float radius, float directionX, float directionY) {
                sprite.setRotation(Tools.radiansToDegrees((float) Math.atan2(directionX, directionY)));
//                sprite.move().with(directionX * radius * 2, directionY * radius * 2);

            }
        });

    }


}